using System;
using System.Windows;
using System.Windows.Data;

namespace ibba.src.sl.recursos.Converters
{
    public class VisibilityToBooleanConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Converter(value, parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Converter(value, parameter);
        }

        private bool Converter(object value, object parameter)
        {
            string operadorNOT = string.Empty;

            if (value == null)
                return false;

            if (parameter != null)
                operadorNOT = parameter.ToString().ToLower();

            if ((parameter != null) && (operadorNOT.Equals("not") || operadorNOT.Equals("!")))
            {
                return (((Visibility)value) == Visibility.Collapsed ? true : false);
            }
            else
            {
                return (((Visibility)value) == Visibility.Visible ? true : false);
            }
        }

        #endregion
    }
}
